//#include <iostream>
//#include <atomic>
//#include <thread>
//#include <vector>   
//
//struct Node {
//	int v;
//	Node* next;
//};
//std::atomic<Node*> head(nullptr);
//
//void append(int v, int n) {
//	for (int i = 0; i < n; i+=3) {
//		Node* oldHead = head;
//		Node* newHead = new Node{ v + i, oldHead };
//		while (!head.compare_exchange_weak(oldHead, newHead)) {
//			newHead->next = oldHead;
//		}
//	}
//}
//
//int main(){
//	std::vector<std::thread> threads;
//	threads.emplace_back(append, 0, 10);
//	threads.emplace_back(append, 20, 10);
//	threads.emplace_back(append, 30, 10);
//	for (auto& th : threads) th.join();
//
//	for (Node* it = head; it != nullptr; it = it->next)
//		std::cout << ' ' << it->v;
//	std::cout << std::endl;
//	
//	Node* it;
//	while (it = head){
//		head = it->next;
//		delete it;
//	}
//	return 0;
//}
